<?php

namespace App\Manage;

use App\Service\Base\Manage;

class SiteAdvManage extends Manage
{
    // 广告
    public function initialize()
    {
        parent::initialize();

        $this->model = 'SiteAdv';
    }

    // 父级
    // 添加，修改，删除，列表，停用 操作


    // 列表查询
    protected function listWhere()
    {
        $opt      = $this->option();
        $space    = $opt->getData('space', 0, 'intval');
        $cate_id  = $opt->getData('cate_id', 0, 'intval');
        $terminal = $opt->getData('terminal', null, 'trim');

        $where = [];
        if($terminal){
            $where[] = ['terminal', '=', $terminal];
        }
        if($space){
            $where[] = ['space', '=', $space];
        }
        if($cate_id){
            $where[] = ['cate_id', '=', $cate_id];
        }

        return $where;
    }

    // 添加
    protected function _before_add()
    {
        $opt  = $this->option();
        $data = [
            'title' => $opt->getData('title', null, 'trim'),
            'space' => $opt->getData('space', 0, 'intval'),
            'rank'  => $opt->getData('rank', 0, 'intval'),

            'pic'      => $opt->getData('pic', null, 'trim'),
            'url'      => $opt->getData('url', null, 'trim'),
            'terminal' => $opt->getData('terminal', 'app', 'trim'),
            'status'   => $opt->getData('status', 1, 'intval'),
            //'cate_id'  => $opt->getData('cate_id', 0, 'intval'),
            //'describe' => $opt->getData('describe', null, 'trim'),
        ];


        return $data;
    }

    // 修改
    protected function _before_edit()
    {
        $opt  = $this->option();
        $data = [
            'title' => $opt->getData('title', null, 'trim'),
            'space' => $opt->getData('space', 0, 'intval'),
            'rank'  => $opt->getData('rank', 0, 'intval'),

            'pic'      => $opt->getData('pic', null, 'trim'),
            'url'      => $opt->getData('url', null, 'trim'),
            'terminal' => $opt->getData('terminal', 'app', 'trim'),
            //'status'   => $opt->getData('status', 1, 'intval'),
        ];


        return $data;
    }

}


